package com.gitee.cui.server.builder;

import com.gitee.cui.common.common.ProtoInstant;
import com.gitee.cui.common.common.bean.msg.ProtoMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 登录响应请求构建器
 * @author cuiqingqiang
 * @version 1.0
 * @date 2021/10/28 8:55
 **/
@Slf4j
@Service
public class LoginResponseBuilder {

    /**
     * 构建登录成功报文
     * @param success 结果码
     * @param sequence 消息序列号
     * @param sessionId sessionId
     * @return 登录成功报文
     */
    public ProtoMsg.Message loginResponse(ProtoInstant.ResultCodeEnum success, long sequence, String sessionId) {
        ProtoMsg.Message.Builder mb = ProtoMsg.Message.newBuilder()
                .setType(ProtoMsg.HeadType.LOGIN_RESPONSE)
                .setSequence(sequence)
                .setSessionId(sessionId);

        ProtoMsg.LoginResponse.Builder rb = ProtoMsg.LoginResponse.newBuilder()
                .setCode(success.getCode())
                .setInfo(success.getDesc())
                .setExpose(1);
        return mb.setLoginResponse(rb.build()).build();
    }
}
